package web.service.Impl;

import web.bean.Chewei;
import web.bean.Dongshu;
import web.dao.CheWeiDao;
import web.dao.DongshuDao;
import web.dao.Impl.CheWeiDaoImpl;
import web.dao.Impl.DongShuDaoImpl;
import web.service.CheWeiService;
import web.service.DongShuService;
import web.vo.PageVo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class DongShuServiceImpl implements DongShuService {
    DongshuDao dongshuDao=new DongShuDaoImpl();
    @Override
    public PageVo<Dongshu> findByInfo(Integer pageSize, Integer pageNo, String startTime, String endTime, String name) {
        Integer params1=(pageNo-1)*pageSize;
        Integer params2=pageSize;
        List<Dongshu> info = dongshuDao.findInfo(params1, params2, startTime, endTime, name);
        int count = dongshuDao.count(startTime, endTime, name);
        PageVo<Dongshu> pageVo=new PageVo<>();
        pageVo.setPageNo(pageNo);
        pageVo.setPageSize(pageSize);
        pageVo.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        pageVo.setCount(count);
        pageVo.setData(info);
        return pageVo;
    }
    public static int number=1;
    @Override
    public int add(Dongshu dongshu) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String s = sdf.format(date);
        String bianhao="XY"+s;
        if (number<10){
            bianhao=bianhao+"00"+number;
            number++;
        } else if (number<100) {
            bianhao=bianhao+"0"+number;
            number++;
        }else {
            bianhao=bianhao+number;
            number++;
        }
        dongshu.setDongshubianhao(bianhao);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        dongshu.setAddtime(format);
        return dongshuDao.add(dongshu);
    }

    @Override
    public int del(Integer[] deleteId) {
        return dongshuDao.del(deleteId);
    }

    @Override
    public Dongshu findNameById(Integer id) {
        return dongshuDao.findNameById(id);
    }

    @Override
    public List<Dongshu> findNameAll() {
        return dongshuDao.findNameAll();
    }

    @Override
    public List<Dongshu> findDongShuAll(Integer id) {
        return dongshuDao.findDongShuAll(id);
    }

    @Override
    public int editInfo(Dongshu dongshu) {
        return dongshuDao.editInfo(dongshu);
    }
}
